home *** CD-ROM | disk | FTP | other *** search
- /*
- CDDiscTime - An XFCN to report the time on disc
- ©Apple Computer, Inc. 1988
- All Rights Reserved.
-
- 88/11/08 BL°B First Version
-
- To compile and link this file using Macintosh Programmer's Workshop,
-
- C -q2 CDDiscTime.c
- link -sn Main=CDDiscTime -sn STDIO=CDDiscTime ∂
- -sn INTENV=CDDiscTime -rt XFCN=42 ∂
- -m CDDiscTime CDDiscTime.c.o "{CLibraries}"CRuntime.o ∂
- "{CLibraries}"StdCLib.o ∂
- -o HyperCommands
-
- This link directive puts the XCMD in the file "HyperCommands".
- Substitute the name of the stack you want it in. To move XCMDs
- between stacks, use ResEdit. They can be in an individual stack,
- the Home stack, the HyperCard application, or the System File.
-
- */
-
- #include <cd.h>
-
- /* prototype definitions for functions */
- OSErr ThisDisc(short, long *, long *, long *);
- void TimeDiff(long *, long *, long *, long, long, long, long, long, long);
-
- /* **** WARNING: DO NOT USE GLOBAL VARIABLES! **** */
-
-
- /************************************************************************
- *
- * Function: CDDiscTime
- *
- * Purpose: return the time of this disc.
- *
- * Returns: either 0, or an error
- * if it's a negative number, it's an error
- *
- * Side Effects:
- *
- * Description: We need one parameter:
- * 1) the ioRefNum that we got from previously calling
- * CDOpen()
- * call the driver with a READTOC call to find out
- * the lead-out time. The disc time is lead-out time
- * minus one block.
- *
- ************************************************************************/
- pascal void
- CDDiscTime(paramPtr)
- XCmdBlockPtr paramPtr;
- {
- Str31 returnString;
- OSErr result;
- short ioRefNum;
- Handle refHandle;
- long discTime[3]; /* minute, second, block */
-
- /* Must be no parameters */
- if ((paramPtr->paramCount) != 0)
- {
- /* Report error in parameters by returning -1 */
- NumToStr(paramPtr, (long) -1, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- return;
- }
-
- /* Get the global ioRefNum and convert it. */
- refHandle = GetGlobal(paramPtr, GLOBALNAME);
- ioRefNum = atoi(*(refHandle));
- DisposHandle(refHandle);
- ioRefNum &= 0xFFFF; /* remove vRefNum; not needed. */
-
- result = ThisDisc(ioRefNum, &discTime[0], &discTime[1], &discTime[2]);
-
- TimeDiff(&discTime[0], &discTime[1], &discTime[2],
- discTime[0], discTime[1], discTime[2], 0, 0, 1); /* disc time is lead-out time minus 1 block */
-
- if (result == noErr)
- {
- /* convert each value to a string, concatenate, & return. */
- FormatString(&returnString, discTime, 3);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- else
- {
- /* We got an error. Convert result to string & return it as error */
- NumToStr(paramPtr, (long) result, &returnString);
- paramPtr->returnValue = PasToZero(paramPtr, (StringPtr) &returnString);
- }
- }
-
- /************************************************************************
- *
- * Function: ThisDisc
- *
- * Purpose: return total time on this disc
- *
- * Returns: OSErr
- * either noErr if everything was okay
- * or some parameter error from driver call.
- *
- * Side Effects:
- * fills in totalMinute, totalSecond, totalBlock
- *
- * Description:
- * call the driver ReadTOC call to get the appropriate
- * information.
- *
- ************************************************************************/
- OSErr
- ThisDisc(refNum, minute, second, block)
- short refNum;
- long *minute;
- long *second;
- long *block;
- {
- CDParam myPB;
- OSErr result;
-
- myPB.ioCompletion = 0;
- myPB.ioNamePtr = (char *) 0;
- myPB.ioVRefNum = 1;
- myPB.ioCRefNum = refNum;
- myPB.csCode = READTOC;
- myPB.csParam[0] = 0;
- myPB.csParam[1] = 2; /* request lead-out time */
-
- result = PBControl(&myPB, false);
-
- if (result == noErr)
- {
- *minute = (long) BCD2DECIMAL(myPB.csParam[0]);
- *second = (long) BCD2DECIMAL(myPB.csParam[1]);
- *block = (long) BCD2DECIMAL(myPB.csParam[2]);
- }
- return result;
- }
-
- /************************************************************************
- *
- * Function: TimeDiff
- *
- * Purpose: calculate difference between two times
- *
- * Returns: nothing
- *
- * Side Effects: fills rMinute, rSecond, rBlock
- *
- * Description: convert the absolute times designated by
- * {m1, s1, f1} and {m2, s2, f2} to absolute
- * blocks. Subtract the second time from the
- * first. Convert the result back to {m, s, f}
- * format.
- *
- ************************************************************************/
- void
- TimeDiff(rMinute, rSecond, rBlock, m1, s1, f1, m2, s2, f2)
- long *rMinute;
- long *rSecond;
- long *rBlock;
- long m1, s1, f1, m2, s2, f2;
- {
- long time1, time2;
- long minute, second, block;
-
- time1 = f1 + (s1 * BLOCKSEC) + (m1 * BLOCKMIN);
- time2 = f2 + (s2 * BLOCKSEC) + (m2 * BLOCKMIN);
-
- time1 = time1 - time2;
-
- minute = time1 / BLOCKMIN;
- time1 = time1 - (minute * BLOCKMIN);
-
- second = time1 / BLOCKSEC;
- block = time1 - (second * BLOCKSEC);
-
- *rMinute = minute;
- *rSecond = second;
- *rBlock = block;
- }
-
- /* C routines for HyperCard callbacks */
- #include <XCmdGlue.inc.c>
-